package com.yl.ylnews;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.yl.ylnews.utils.PrefUtil;

public class SplashActivity extends Activity {

    private android.widget.ImageView ivsplashbg;
    private android.widget.RelativeLayout activitysplash;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        /*//初始化xUtils
        x.Ext.init(getApplication());
        x.Ext.setDebug(BuildConfig.DEBUG);*/

      /*  x.Ext.init(this);
        x.Ext.setDebug(BuildConfig.DEBUG); // 是否输出debug日志, 开启debug会影响性能.*/

        this.activitysplash = (RelativeLayout) findViewById(R.id.activity_splash);
        this.ivsplashbg = (ImageView) findViewById(R.id.iv_splash_bg);

        RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f
                , Animation.RELATIVE_TO_SELF, 0.5f);
        ra.setDuration(1000);
        ScaleAnimation sa = new ScaleAnimation(0.3f, 1, 0.3f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        sa.setDuration(1000);
        AlphaAnimation aa = new AlphaAnimation(0.3f, 1.0f);
        aa.setDuration(2000);//这里设置2秒可用造成Splash界面短暂的停留

        AnimationSet set = new AnimationSet(true);
        set.addAnimation(ra);
        set.addAnimation(sa);
        set.addAnimation(aa);

        activitysplash.startAnimation(set);

        set.setAnimationListener(new Animation.AnimationListener() {//设置动画监听器
            @Override
            public void onAnimationStart(Animation animation) {

            }

            //动画结束后调用
            @Override
            public void onAnimationEnd(Animation animation) {
                boolean isFirst = PrefUtil.getSharedPerenceBoolean(SplashActivity.this, "is first enter", true);
                Intent intent;
                if (isFirst) {
                    intent = new Intent(SplashActivity.this, GuideActivity.class);
                } else {
                    intent = new Intent(SplashActivity.this, MainActivity.class);
                }
                startActivity(intent);
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });


    }
}
